<?php
/*
 * @copyright        [YouNet_COPYRIGHT]
 * @author           YouNet Company
 * @package          Module_Contactimporter
 * @version          2.06
 *
 */
defined('PHPFOX') or exit('NO DICE!');
if (file_exists(PHPFOX_DIR.'module'.PHPFOX_DS.'contactimporter'.PHPFOX_DS.'include'.PHPFOX_DS.'component'.PHPFOX_DS.'controller'.PHPFOX_DS.'openinviter'.PHPFOX_DS.'openinviter.php'))
{
    require_once(PHPFOX_DIR.'module'.PHPFOX_DS.'contactimporter'.PHPFOX_DS.'include'.PHPFOX_DS.'component'.PHPFOX_DS.'controller'.PHPFOX_DS.'openinviter'.PHPFOX_DS.'openinviter.php');
}
?>
<?php
class ContactImporter_Component_Controller_Email extends Phpfox_Component
{
   	public function process()
	{        
        Phpfox_Error::skip(true);	                
        $sProvider = $this->request()->get('req2');
        $iPage = $this->request()->get('page', 1);        
        $iLimit = $iMaxInvitation = Phpfox::getService('contactimporter')->getMaxInvitation();
        $iOffset = ($iPage - 1) * $iLimit;
        
        if ($sProvider == 'yahoo')
        {                      
            list($iCnt, $aInviteLists, $aJoineds, $aErrors) = Phpfox::getService('contactimporter.yahoo')->get($iPage, $iLimit);  
        }
        elseif ($sProvider == 'gmail')
        {                      
            list($iCnt, $aInviteLists, $aJoineds, $aErrors) = Phpfox::getService('contactimporter.gmail')->get($iPage, $iLimit);  
        }
        elseif ($sProvider == 'hotmail')
        {                      
            list($iCnt, $aInviteLists, $aJoineds, $aErrors) = Phpfox::getService('contactimporter.hotmail')->get($iPage, $iLimit);  
        }
        else
        {
           list($iCnt, $aInviteLists, $aJoineds, $aErrors) = Phpfox::getService('contactimporter.openinviter')->get($sProvider, $iPage, $iLimit);   
        }
        
        if (isset($aErrors['login']) && $aErrors['login'])
        {            
            $this->url()->send('contactimporter', null, $aErrors['login']);
            exit;
        }         
        if (isset($aErrors['contacts']) && $aErrors['contacts'])
        {            
            $this->url()->send('contactimporter', null, $aErrors['contacts']);
            exit;
        } 
        $this->template()->setHeader(array(
            'importer.css' => 'module_contactimporter',                                
            'common.js'=>'module_contactimporter',
            'importer.js'=>'module_contactimporter',
        ));          
        $this->template()->assign(array(                
            'iCnt' => $iCnt,                
            'iLimit' => $iLimit,                
            'iPage' => $iPage,                
            'sProvider' => $sProvider,                
            'aInviteLists' => $aInviteLists,                
            'aJoineds' => $aJoineds,                
            'aError' => $aErrors,
            'sCoreUrl' => Phpfox::getParam('core.path'),
            'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
        ));       
                // Loading feed
        $this->template()->setHeader('cache', array(
                    'sort.js' => 'module_theme',
                    'design.js' => 'module_theme',
                    'video.css' => 'module_video'
                        )
        );
        $this->template()->setHeader('cache', array(
                    'feed.js' => 'module_feed',
                    'welcome.css' => 'style_css',
                    'announcement.css' => 'style_css',
                    'comment.css' => 'style_css',
                    'quick_edit.js' => 'static_script',
                    'jquery/plugin/jquery.highlightFade.js' => 'static_script',
                    'jquery/plugin/jquery.scrollTo.js' => 'static_script'
                        )
                )
                ->setEditor(array(
                    'load' => 'simple'
                        )
        );

        Phpfox::getLib('pager')->set(array('page' => $iPage, 'size' => $iLimit, 'count' => $iCnt));
    }
}
?>